# Create your views here.
from django.shortcuts import render_to_response, get_object_or_404
from weblog.models import  Author, Entry, About,Category
from django.template import Context, loader, RequestContext
from django.http import Http404, HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse

def index(request):
    latest_entry = Entry.objects.order_by('-pub_date')[:6]
    most_rate = Entry.objects.order_by("rating")[:8]
    most_category=Category.objects.all()
    pack={}
    pack['latest_entry']=latest_entry
    pack['most_rate']=most_rate
    pack['most_category']=most_category
#    return render_to_response('index.html', {'latest_entry': latest_entry})
    return render_to_response('index.html', pack)

def detail(request, entry_id):
    entry=get_object_or_404(Entry,pk=entry_id)
    most_rate = Entry.objects.order_by("rating")[:8]
    most_category=Category.objects.all()
    pack={}
    pack['entry']=entry
    pack['most_rate']=most_rate
    pack['most_category']=most_category
#    entry.body_text=entry.body_text.replace("\n","\u003cbr /\u003e")
    return render_to_response("detail.html",pack,context_instance=RequestContext(request))

def about(request):
    about=get_object_or_404(About,pk=1)
    return render_to_response("about.html",{'about':about})
#
